import Vue from 'vue'
import App from '@/App'
import router from '@/router'
import store from '@/store'
import VueCookie from 'vue-cookie'
// 如果element不够用导入Elemment
// import Element from 'element-ui'
import '@/element-ui'
import '@/icons'
import '@/element-ui-theme'
import '@/assets/scss/index.scss'
import '@/assets/scss/descriptions.scss'
import '@/assets/scss/descriptions-item.scss'
import '@/assets/scss/timeline-item.scss'
import '@/assets/scss/timeline.scss'
import '@/assets/scss/divider.scss'
import httpRequest from '@/utils/httpRequest'
import { isAuth } from '@/utils'
import cloneDeep from 'lodash/cloneDeep'
// Vue.use(Element)
Vue.use(VueCookie)

Vue.config.productionTip = false


// 非生产环境, 适配mockjs模拟数据
// if (process.env.NODE_ENV !== 'production') {
//   require('@/mock')
// }

// 挂载全局
Vue.prototype.$http = httpRequest // ajax请求方法
Vue.prototype.isAuth = isAuth     // 权限方法

// 保存整站vuex本地储存初始状态
window.SITE_CONFIG['storeState'] = cloneDeep(store.state)
Vue.prototype.resetSetItem = function (key, newVal) {
  if (key === 'menuList') {
    // 创建一个StorageEvent事件
    let newStorageEvent = document.createEvent('StorageEvent')
    const storage = {
      setItem: function (k, val) {
        sessionStorage.setItem(k, val)
        // 初始化创建的事件
        newStorageEvent.initStorageEvent('setItem', false, false, k, null, val, null, null)
        // 派发对象
        window.dispatchEvent(newStorageEvent)
      }
    }
    return storage.setItem(key, newVal);
  }
}

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
